package apiooday01;

public class StringBuilderDemo {
    public static void main(String[] args) {
        //string的类型转换为StringBuilder，StringBuilder修改更快速，节省内存

//        long start = System.currentTimeMillis();
//        for (int i=0;i<1000000;i++){
//            str+=i;
//            System.out.println(2);
//        }
//        long end = System.currentTimeMillis();
//        System.out.println("时间:"+(end - start));
//        System.out.println("ok");
        System.out.println("----------------");
        String str ="123";//123在常量池
        String str1="123";//123在常量池
        System.out.println(str==str1);

      //  重写了所以为true：
        System.out.println(str.equals(str1));
//        point point =new point(100,200);
//        System.out.println(point);

        StringBuilder strb=new StringBuilder("321");
        StringBuilder strb1=new StringBuilder("321");

        System.out.println(strb==strb1);
       // 没有重写所以为false：
        System.out.println(strb.equals(strb1));

        System.out.println(strb);

        StringBuilder builder =new StringBuilder(str);
        StringBuilder builder1 =new StringBuilder(str1);

        // StringBuilder默认重写toString
        String sss=builder.toString();
        String sss1=builder1.toString();

        System.out.println(sss.equals(sss1));//所以为true
        System.out.println("----------------------");

        System.out.println(builder.length());
        builder.append("456");//追加字符串456


        System.out.println(builder);//123456
        builder.replace(3,7,"789");//替换成789



        System.out.println(builder);//123789
        builder.delete(4,6);//删除某段字符串



        System.out.println(builder);//1237
        builder.insert(1,987);//插入987



       // String str2=builder.toString();
       // builder.reverse();//倒序输出
     //   System.out.println(str2);
        for (int i=0;i<10000000;i++){
            builder.append(i);
        }
        System.out.println("okok");
    }
}
